<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <title>我的购物车 - 企业培训平台</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        .cart-item {
            border: 1px solid #ddd;
            padding: 15px;
            margin-bottom: 15px;
            border-radius: 8px;
            background-color: #fff;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .cart-item-details {
            flex-grow: 1;
        }
        .cart-item-details h3 {
            margin-top: 0;
            color: #333;
            font-size: 1.2em;
        }
        .cart-item-details p {
            color: #666;
            font-size: 0.9em;
            margin-bottom: 5px;
        }
        .cart-item-details .price {
            font-weight: bold;
            color: #007bff;
            font-size: 1.1em;
        }
        .cart-item-actions {
            display: flex;
            gap: 10px;
        }
        .cart-summary {
            margin-top: 30px;
            padding: 20px;
            background-color: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 8px;
            text-align: right;
            font-size: 1.2em;
            font-weight: bold;
        }
        .cart-summary .total-actions {
            margin-top: 15px;
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }
        .no-results-message {
            padding: 20px;
            text-align: center;
            color: #6c757d;
            background-color: #e9ecef;
            border-radius: 8px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div th:replace="~{fragments/header :: common-header}"></div>

<div class="main-content">
    <div class="container">
        <h1 class="page-title">我的购物车</h1>

        <div th:if="${successMessage}" class="alert alert-success">
            <p th:text="${successMessage}"></p>
        </div>
        <div th:if="${errorMessage}" class="alert alert-danger">
            <p th:text="${errorMessage}"></p>
        </div>

        <div th:if="${!#lists.isEmpty(cartItems)}">
            <div class="cart-items-list">
                <div class="cart-item" th:each="item : ${cartItems}">
                    <div class="cart-item-details">
                        <h3 th:text="${item.couName}">课程名称占位符</h3>
                        <p th:text="${item.couIntroduction}">课程介绍占位符。</p>
                        <p class="price">价格: <span th:text="${item.couPrice != null ? item.couPrice + ' 积分' : '免费'}">价格占位符</span></p>
                    </div>
                    <div class="cart-item-actions">
                        <form th:action="@{/student/cart/remove/{cartItemId}(cartItemId=${item.id})}" method="post" style="display: inline;">
                            <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('确定要从购物车中移除这门课程吗？');">移除</button>
                        </form>
                    </div>
                </div>
            </div>

            <div class="cart-summary">
                <p>当前积分: <span th:text="${student.stuScore}">学生积分占位符</span></p>
                <p>总计: <span th:text="${totalPrice}">总价格占位符</span> 积分</p>
                <div class="total-actions">
                    <form th:action="@{/student/cart/purchaseAll}" method="post" style="display: inline;">
                        <button type="submit" class="btn btn-primary" onclick="return confirm('确定要购买购物车中所有课程吗？');">立即购买所有课程</button>
                    </form>
                </div>
            </div>
        </div>

        <div th:if="${#lists.isEmpty(cartItems)}" class="no-results-message">
            <p>您的购物车是空的。</p>
            <a th:href="@{/student/courses/browse}" class="btn btn-primary">去浏览课程</a>
        </div>
    </div>
</div>
</body>
</html>